class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:

        if root is None:
            return True

        def f(a:TreeNode,b:TreeNode):
            if a is None or b is None:
                return a == b
            if a.val != b.val:
                return False
            return f(a.left,b.right) and f(a.right,b.left)
        
        return f(root.left,root.right)